package org.jeecg.modules.yw.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.yw.entity.EnterPrise;
import org.jeecg.modules.yw.entity.UserView;
import org.jeecg.modules.yw.vo.EnterPriseVo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

@Mapper
public interface EnterPriseMapper extends BaseMapper<EnterPrise> {

    @Select("SELECT  id,name,province,city,picture,mobile,password,roleId,isLeader,createTime,createUser,delFlag,approve,reason,approveTime  FROM enterprise")
    List<EnterPrise> findAll();


    @Select("Select * FROM enterprise where mobile = #{mobile} and password = #{password} and delFlag = 0")
    EnterPrise login(@Param("mobile") String mobile, @Param("password") String password);

    IPage<EnterPriseVo> pageEnter(Page<EnterPrise> page, @Param(Constants.WRAPPER) LambdaQueryWrapper<EnterPrise> queryWrapper);
    
    
    @Select("Select password FROM enterprise where mobile = #{mobile} and delFlag = 0 limit 0,1")
    String getPasswordByMobile(@Param("mobile") String mobile);
    
    
    @Select("Select id FROM enterprise where mobile = #{mobile} and delFlag = 0 limit 0,1")
    String getIdByMobile(@Param("mobile") String mobile);

    List<EnterPrise> selectZzList(@Param("datestr") String datestr, @Param("areas") String[] areas,@Param("provinceCode") String provinceCode,@Param("cityCode") String cityCode);

    List<EnterPrise> selectDjshList(@Param("datestr") String datestr, @Param("areas") String[] areas,@Param("provinceCode") String provinceCode,@Param("cityCode") String cityCode);
    
    List<EnterPrise> selectMcqy(@Param("datestr") String datestr, @Param("areas") String[] areas,@Param("provinceCode") String provinceCode,@Param("cityCode") String cityCode);
    

    /**
     * 查询关联用户
     * @param
     * @return
     */
    @Select("SELECT id from view_userroleinfo where realname='管理员'")
    List<UserView> selectUsers();
    
    

    /**
     * 查询关联城市
     * @param
     * @return
     */
    @Select("SELECT id from view_userroleinfo where area in (#{cityCode}) and role_id = 'nqzg'")
    List<UserView> selectUserByCityCode(@Param("cityCode") String cityCode);
    
    
    @Update("update enterprise set refreshToken = #{refreshToken} where id = #{id}")
    int updateToken(@Param("id") String id, @Param("refreshToken") String refreshToken);
}
